package com.tom.websocket;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * websocket服务端
 *
 * @author zx
 * @date 2024-10-04 15:38
 */
public class WebSocketServer {
    public static void main(String[] args) {
        EventLoopGroup mainGroup = new NioEventLoopGroup();
        EventLoopGroup subGroup = new NioEventLoopGroup();

       try {
           ServerBootstrap server = new ServerBootstrap();
           server.group(mainGroup,subGroup)
                   .channel(NioServerSocketChannel.class)
                   .childHandler(new WebSocketInitializer());

           ChannelFuture channelFuture = server.bind(8088).sync();
           channelFuture.channel().closeFuture().sync();
       }catch(Exception e){
           e.printStackTrace();
       }finally {
           mainGroup.shutdownGracefully();
           subGroup.shutdownGracefully();
       }


    }
}
